import 'package:xuance/bean/LoginHistoryBean.dart';
import 'package:xuance/bean/UserBean.dart';
import 'package:xuance/network/network_service.dart';
import 'package:xuance/util/cache_util.dart';

class UserApi {
  static Future<UserBean?> login(
      {required String account, required String password}) async {
    var res = await NetworkService.post(url: "sysUser/sysLogin", map: {
      "userCode": account,
      "password": password,
      "resourceType": "app"
    });
    var user = res.getTypedData((m) => UserBean.fromJson(m));
    await CacheUtil.setToken(user?.token);
    await CacheUtil.setUser(user);
    return user;
  }

  static Future<LoginHistoryBean?> loginHistory(
      String? userCode, currentPage) async {
    var res = await NetworkService.post(
        url: "login-detail/queryLoginDetailList",
        map: {
          "userCode": userCode,
          "pageSize": 10,
          "currentPage": currentPage,
        });
    return res.getTypedData((m) => LoginHistoryBean.fromJson(m));
  }
}
